'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const sys_dept = app.model.define('sys_dept', {
    deptId: {
      type: INTEGER,
      comment: "部门id",
      primaryKey: true,
      autoIncrement: true,
      field:"dept_id"
    },
    parentId: {
      type: INTEGER,
      comment: "父部门",
      defaultValue: 0,
      field:"parent_id"
    },
    ancestors: {
      type: STRING(50),
      comment: "祖级列表"
    },
    deptName: {
      type: STRING(30),
      comment: "部门名称",
      field:"dept_name"
    },
    orderNum: {
      type: INTEGER(4),
      comment: "显示顺序",
      field:"order_num"
    },
    leader: {
      type: STRING(20),
      comment: "负责人"
    },
    phone: {
      type: STRING(11),
      comment: "联系电话"
    },
    email: {
      type: STRING(50),
      comment: "邮箱"
    },
    status: {
      type: STRING(1),
      comment: "部门状态（0正常 1停用）"
    },
    createBy:{
      type:STRING(64),
      comment:"创建者",
      field:"create_by"
    },
    createTime:{
      type:DATE,
      field:"created_at"
    }
  }, {
    paranoid: true,
    freezeTableName: true
  });

  sys_dept.associate = ()=>{
    app.model.SysDept.belongsToMany(app.model.SysRole,{
      through:app.model.SysRoleDept
    });
  }

  return sys_dept;
};